﻿Public Class ucCalibre
    Private tipoArmaBo As New tipo_armaBO
    Private calibreBO As New calibreBO
    Private armaBO As New armaBO

    Public Property DESCARMA() As String
        Get
            Return cmbTipoArma.Text
        End Get
        Set(value As String)
            cmbTipoArma.Text = value
        End Set
    End Property
    Public Property DESCCALIBRE() As String
        Get
            Return cmbCalibre.Text
        End Get
        Set(value As String)
            cmbCalibre.Text = value
        End Set
    End Property

    Public Property GETTIPOARMA() As Integer
        Get
            Return cmbTipoArma.SelectedValue
        End Get
        Set(value As Integer)
            cmbTipoArma.SelectedValue = value
        End Set
    End Property

    Public Property GETIDCALIBRE() As Integer
        Get
            Return cmbCalibre.SelectedValue
        End Get
        Set(value As Integer)
            cmbCalibre.SelectedValue = value
        End Set
    End Property


    Private Sub ucCalibre_Load(sender As Object, e As EventArgs) Handles Me.Load
        Try
            cmbTipoArma.DisplayMember = "DESC_TIPO_ARMA"
            cmbTipoArma.ValueMember = "ID_TIPO_ARMA"
            cmbTipoArma.DataSource = armaBO.getArmas
            cmbTipoArma.SelectedIndex = 0
            populaCalibres(cmbTipoArma.SelectedValue)
        Catch ex As Exception
            generica.gravaErro(ex)
        End Try
    End Sub
    Private Sub populaCalibres(ByVal id_tipo_arma As Integer)

        Dim EHESPINGARDA As Boolean

        If cmbTipoArma.SelectedValue = 3 Then
            EHESPINGARDA = True
        Else
            EHESPINGARDA = False
        End If
        Try
            Dim calibreBO As New calibreBO
            'If Not cmbTipoArma.SelectedValue = 3 Then
            cmbCalibre.DisplayMember = "CALIBRE"
            cmbCalibre.ValueMember = "ID_CALIBRE"
            cmbCalibre.DataSource = calibreBO.getCalibres(EHESPINGARDA)
            ' Else
            'cmbCalibre.DataSource = Nothing

            'End If
        Catch ex As Exception
            generica.gravaErro(ex)
        End Try

    End Sub
    Private Sub cmbTipoArma_SelectedIndexChanged_1(sender As Object, e As EventArgs) Handles cmbTipoArma.SelectedIndexChanged
        Try
                populaCalibres(cmbTipoArma.SelectedValue)

        Catch ex As Exception
            generica.gravaErro(ex)
        End Try
    End Sub
End Class
